package com.ruowei.modules.sys.web;

import com.ruowei.config.Constants;
import com.ruowei.modules.sys.repository.TodoRepository;
import com.ruowei.modules.sys.web.dto.TodoDTO;
import com.ruowei.security.CurrentUser;
import com.ruowei.security.UserModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/api")
@Transactional
@Api(tags = Constants.TAG_TODO)
public class TodoResource {

    private final TodoRepository todoRepository;

    public TodoResource(TodoRepository todoRepository) {
        this.todoRepository = todoRepository;
    }

    @GetMapping("/todos/mine")
    @ApiOperation(value = "我的待办事项", notes = "作者：李春浩")
    public ResponseEntity<List<TodoDTO>> getMineTodos(@ApiIgnore @CurrentUser UserModel userModel) {
        return ResponseEntity.ok(todoRepository.getAllMineTodos(userModel.getUserCode()));
    }
}
